package demo2;
//写一个泛型类，求一个泛型数组当中的最大值
//将来传入的T 一定是实现了 Comparable 接口的
class Alg<T extends Comparable<T>>{
    public T findMax(T[] array){
        T max = array[0];
        for(int i = 1; i < array.length;i++){
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}
class Student implements Comparable<Student>{
    @Override
    public int compareTo(Student o) {
        return 0;
    }
}
class Alg2{
    //泛型方法
    public<T extends Comparable<T>> T findMax(T[] array){
        T max = array[0];
        for(int i = 1;i < array.length; i++){
            if(max.compareTo(array[i])<0){
                max = array[i];
            }
        }
        return max;
    }
}
class Alg3{
    //泛型方法
    public static <T extends Comparable<T>> T findMax(T[] array){
        T max = array[0];
        for(int i = 1;i < array.length; i++){
            if(max.compareTo(array[i])<0){
                max = array[i];
            }
        }
        return max;
    }
}
public class Test2 {
    public static void main(String[] args) {
    }
    public static void main2(String[] args) {
        Integer[] arr = new Integer[]{1,2,4,5,66};
        Alg2 alg2 = new Alg2();
        Integer ret=  alg2.<Integer>findMax(arr);
        System.out.println(ret);

        Integer ret3 = Alg3.<Integer>findMax(arr);
        System.out.println(ret3);


    }
    public static void main1(String[] args) {
        Integer[] arr = new Integer[]{1,3,5,2,57,53};
        Alg<Integer> alg = new Alg<>();
        Integer ret = alg.findMax(arr);
        System.out.println(ret);
    }
}
